package router

import (
	"bluebell-backend/controller"
	"bluebell-backend/middlewares"
	"github.com/gin-gonic/gin"
	"net/http"
)

func InitRouter() *gin.Engine {
	gin.SetMode(gin.ReleaseMode)
	r := gin.Default()

	v1 := r.Group("/api/v1")

	{
		v1.POST("/register", controller.Register)
		v1.POST("/login", controller.Login)
	}

	v1User := v1.Group("/user")
	v1User.Use(middlewares.JWTAuthMiddleware())
	{
		v1User.POST("/update", controller.UpdateUserInfo)
		v1User.GET("/info", controller.GetUserInfo)
	}

	v1Category := v1.Group("/category")
	v1Category.Use(middlewares.JWTAuthMiddleware())
	{
		v1Category.POST("/add", controller.AddCateGory)
		v1Category.GET("/delete/:id", controller.DeleteCategory)
		v1Category.GET("/info/:id", controller.GetCategoryInfo)
		v1Category.GET("/list")
		v1Category.POST("/update", controller.UpdateCategoryInfo)
		v1Category.GET("/get-post/:id", controller.GetAllPostByCategoryId)
	}

	v1Post := v1.Group("/post")
	v1Post.Use(middlewares.JWTAuthMiddleware())
	{

		v1Post.POST("/update", controller.UpdatePost)
		v1Post.GET("/info/:id", controller.GetPostInfo)

	}
	v1Vote := v1.Group("/post")
	v1Vote.Use(middlewares.JWTAuthMiddleware())
	{
		// 投票
		v1Vote.POST("/vote", controller.PostVoteController)

		v1Vote.POST("/add", controller.AddPost)
	}

	r.NoRoute(func(c *gin.Context) {
		c.JSON(http.StatusOK, gin.H{
			"code": "404",
		})
	})
	return r
}
